/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpaintball;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.NoninvertibleTransformException;

/**
 *
 * @author ondra
 */
abstract public class GameObject {

    protected Position position;
    private boolean destroyed;

    GameObject(int x, int y, int width, int height, int poleX, int poleY, double angle) {
        position = new Position(x, y, width, height, poleX, poleY, angle);
        destroyed = false;
    }

    final public void draw(Graphics2D g2d) {
        AffineTransform af = new AffineTransform();
        af.rotate(position.getAngle(),position.getPoleX(),position.getPoleY());
        g2d.transform(af);
        drawSprite(g2d);
        try {
            g2d.transform(af.createInverse());
        } catch (NoninvertibleTransformException ex) {}
    }

    abstract protected void drawSprite(Graphics2D g2d);

    public Area getArea() {
        return position.getArea();
    }
    public boolean isDestroyed() {
        return destroyed;
    }

    protected void Destroy() {
        this.destroyed = true;
    }

}
